local sk__jijun = fk.CreateSkill {

  name = "sk__jijun",

  tags = {},

}



sk__jijun:addEffect("active", {
  name = "sk__jijun",
  anim_type = "special",
  min_card_num = 1,
  target_num = 0,
  prompt = "#sk__jijun",
  derived_piles = "sk__zhangliang__bing",
  expand_pile = "sk__zhangliang__bing",
  can_use = function(self, player)
    return player:usedSkillTimes(sk__jijun.name, Player.HistoryPhase) == 0
  end,
  target_filter = Util.FalseFunc,
  card_filter = function(self, player, to_select, selected)
    return #selected < 4 and Fk:currentRoom():getCardArea(to_select) == Player.Hand and
        table.every(selected, function(id)
          return Fk:getCardById(to_select).suit ~= Fk:getCardById(id).suit
        end)
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local cards = table.filter(player:getPile("sk__zhangliang__bing"), function(id)
      return table.find(effect.cards, function(id2)
        return Fk:getCardById(id).suit == Fk:getCardById(id2).suit and Fk:getCardById(id).suit ~= Card.NoSuit
      end) ~= nil
    end)
    if #cards == 0 then
      player:addToPile("sk__zhangliang__bing", effect.cards, true, sk__jijun.name, player.id)
    else
      room:swapCardsWithPile(player, effect.cards, cards, sk__jijun.name, "sk__zhangliang__bing", true, player.id)
    end
    if player.dead then return end
    local use = room:askToUseVirtualCard(player, {
      name = Fk:getAllCardNames("b"),
      prompt = "#sk__jijun-use",
      cancelable = true,
      skip = true,
      skill_name = sk__jijun.name,
      extra_data = {
        bypass_times = true,
        bypass_distances = true,
      },
    })
    if use then
      room:useCard(use)
    end
  end,
})

return sk__jijun
